<?
	global $items,$owner,$group;
	
	$writeable = true;
	$has_dirs = false;
	$is_root = is_root();
	
	if($multi = (count($items) >1)){
		$icon = 'multiple.png';
		$name = 'multiple items';
		$mime = '';
		$classtitle = count($items) . ' items';
		$fs = 0;
		foreach($items as $item){
			$fs += $item->filesize;
			if($item->dir) $has_dirs = true;
			if(!$item->is_writable) $writeable = false;
		}
	}else{
		$file = $items[0];
		$has_dirs = $file->dir;
		$icon = $file->icon(128);
		$basename = $file->basename;
		$name = $file->name;
		$mime = $file->mime;
		$classtitle = $file->media_class;
		$fs = $file->filesize;
		$writeable = $file->is_writable;
	}
			
	$icon = ($multi || $file->class != 'app') ? $this->icon($icon) : SHR.'/Apps/'.$file->modpath.'/images/128/'.$icon;
	$fs = bytesize($fs);
?>

<div id="browse-bigicon" style="background:url(<?=$icon?>) center center no-repeat; height:128px; width:128px; float:left"></div>
<div align="right" style="margin:0 5px 0 0; min-height:128px">
	<input id="browse-name" readonly="readonly" style="border:none; font-size:2em; font-weight:bold; width:460px; text-align:right" value="<?=$name?>" />
	<br />
	<br />
	<em id="browse-classtitle"><?=$classtitle?> </em> 
	<br />
	<? if($mime){ ?>
	<em><?=$mime?></em>
	<br /><br />
	<? } ?>
	<strong id="browse-filesize"><?=$fs?></strong><br />
</div>
<br /><br />
<em>There are no options for converting this file</em>
<br /><br /><br /><br />
<? if($is_root){ 

	$stb = true;

	if($multi){
		$owners = array();
		$groups = array();
		$umods = array();
		$gmods = array();
		$wmods = array();
		foreach($items as $item){
			if(!$item->stb) $stb = false;
			$owners[$item->own] = true;
			$groups[$item->grp] = true;
			$m = str_split($item->mode);
			$umods[$m[0]] = true;
			$gmods[$m[1]] = true;
			$wmods[$m[2]] = true;
		}
		$owner = (!(count($owners) > 1)) ? new obj(array('id'=>$item->own(), 'name'=>smdb($item->own())->name)) : new obj(array('id'=>'', 'name'=>'* multiple owners'));
		$group = (!(count($groups) > 1)) ? new obj(array('id'=>$item->grp(), 'name'=>smdb($item->grp())->name)) : new obj(array('id'=>'', 'name'=>'* multiple groups'));
		$umod = (!(count($umods) > 1)) ? key($umods) : '*';
		$gmod = (!(count($gmods) > 1)) ? key($gmods) : '*';
		$wmod = (!(count($wmods) > 1)) ? key($wmods) : '*';
		
	}else{
		$stb = $file->stb;
		$own = smdb($file->own());
		$grp = smdb($file->grp());
		$owner = new obj(array('id'=>$file->own(), 'name'=>$own->name));
		$group = new obj(array('id'=>$file->grp(), 'name'=>$grp->name));
		list($umod, $gmod, $wmod) = str_split($file->mode());
	}

	function browse_modeText($i){
		switch(1){
			case ($i && $i == '*'):
				return array('k'=>'na', 'txt'=>'* mixed modes');
			case ($i >= 6):
				return array('k'=>'rw', 'txt'=>'Read And Write');
			case ($i >= 4):
				return array('k'=>'ro', 'txt'=>'Read Only');
			case ($i >= 2):
				return array('k'=>'wo', 'txt'=>'Write Only');
			default:
				return array('k'=>'na', 'txt'=>'Not Access');
		}
	}

	$own_perms = browse_modeText($umod);
	$grp_perms = browse_modeText($gmod);
	$wrl_perms = browse_modeText($wmod);

?>
<div id="browse-perms-edits" style="display:none">
	<table id="browse-perms-table" align="center" border="0" cellpadding="0" cellspacing="4">
		<tbody>
			<tr>
				<td align="right">
					
				</td>
				<td align="right" valign="top" width="200">
					<div id="ownername-clear" class="button16 removeicon" style="margin:4px 0 0 -5px; display:none"></div>
					<label for="ownername" id="ownername-link"><?=$owner->name?></label>
					<input type="text" id="ownername" value="<?=$owner->name?>" style="display:none" />
				</td>
				<td>
					<small>can</small>
				</td>
				<td align="left" valign="top" width="200">
					<div id="ownerperms-clear" class="button16 removeicon" style="margin:4px 0 0 184px; display:none"></div>
					<label for="ownerperms" id="ownerperms-link"><?=$own_perms['txt']?></label>
					<select id="ownerperms" style="display:none">
						<? 	
							foreach(array(6, 4, 2, 0) as $n){
								$n = browse_modeText($n);
								echo '<option value="'.$n['k'].'"';
								if($n['k'] == $own_perms['k']) echo ' selected="selected"';
								echo '>'.$n['txt'].'</option>';
							}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td align="right">
					
				</td>
				<td align="right" valign="top">
					<div id="groupname-clear" class="button16 removeicon" style="margin:4px 0 0 -5px; display:none"></div>
					<label for="groupname" id="groupname-link"><?=$group->name?></label>
					<input type="text" id="groupname" value="<?=$group->name?>" style="display:none" />
				</td>
				<td>
					<small>can</small>
				</td>
				<td align="left" valign="top" width="200">
					<div id="groupperms-clear" class="button16 removeicon" style="margin:4px 0 0 184px; display:none"></div>
					<label for="groupperms" id="groupperms-link"><?=$grp_perms['txt']?></label>
					<select id="groupperms" style="display:none">
						<? 	
							foreach(array(6, 4, 2, 0) as $n){
								$n = browse_modeText($n);
								echo '<option value="'.$n['k'].'"';
								if($n['k'] == $grp_perms['k']) echo ' selected="selected"';
								echo '>'.$n['txt'].'</option>';
							}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td align="right">
					
				</td>
				<td align="right" valign="top">
					<input type="text" value="The Whole World" readonly="readonly" />
				</td>
				<td>
					<small>can</small>
				</td>
				<td align="left" valign="top" width="200">
					<div id="worldperms-clear" class="button16 removeicon" style="margin:4px 0 0 184px; display:none"></div>
					<label for="worldperms" id="worldperms-link"><?=$wrl_perms['txt']?></label>
					<select id="worldperms" style="display:none">
						<? 	
							foreach(array(6, 4, 2, 0) as $n){
								$n = browse_modeText($n);
								echo '<option value="'.$n['k'].'"';
								if($n['k'] == $wrl_perms['k']) echo ' selected="selected"';
								echo '>'.$n['txt'].'</option>';
							}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="4" align="center" style="padding:5px; margin:5px; background-color:#f9f9f9; border-bottom:1px dashed #ddd;<? if(!$is_root){ ?>display:none<? } ?>">
					<? if($is_root){ ?><img src="<?=Screen()->icon('Root.png', 32)?>" style="float:left" /><? } ?>
					<sup>mode:</sup> <input type="text" id="browse-mode" value="***" style="width:2.2em" /> &nbsp; 
					<span<? if($multi || !$has_dirs){ ?> style="display:none"<? } ?>>
					<sup>apply recursive:</sup> <input type="checkbox" id="browse-rcr" value="1" /> &nbsp; 
					</span> 
					<sup>sticky bit:</sup> <input type="checkbox" id="browse-stb" value="1" <? if($stb){ ?>checked="checked" <? } ?>/ >
					<input type="button" value="save" style="float:right; margin-top:5px" onclick="PermsSet.save()" />
				</td>
			</tr>
			
		</tbody>
	</table>
</div>
<? } ?>
